import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'Frame',
    component: () => import("../views/MainFrame.vue"),
    meta: {
      title: "书程小驿",
      keepAlive: true
    },
    children: [
      {
        path: '/',
        name: 'Frame',
        component: () => import(/* webpackChunkName: "about" */ '../components/Major/Home.vue'),
        meta: {
          title: "首页 ● 书程小驿",
          keepAlive: true
        }
      },
      {
        path: '/categories',
        name: 'Categories',
        component: () => import(/* webpackChunkName: "about" */ '../components/Major/Categories.vue'),
        meta: {
          title: "分类 ● 书程小驿",
          keepAlive: true
        }
      },
      {
        path: '/collect',
        name: 'Collect',
        component: () => import(/* webpackChunkName: "about" */ '../components/Major/Collect.vue'),
        meta: {
          title: "收藏夹 ● 书程小驿",
          keepAlive: true
        }
      },
      {
        path: '/shopCart',
        name: 'ShopCart',
        component: () => import(/* webpackChunkName: "about" */ '../components/Major/ShopCart.vue'),
        meta: {
          title: "购物车 ● 书程小驿",
          keepAlive: true
        }
      },
      {
        path: '/bookDetail',
        name: 'BookDetail',
        component: () => import(/* webpackChunkName: "about" */ '../components/Major/BookDetail.vue'),
        meta: {
          title: "详情页 ● 书程小驿",
          keepAlive: true
        }
      },
      {
        path: '/borrowDetail',
        name: 'BorrowDetail',
        component: () => import(/* webpackChunkName: "about" */ '../components/Major/BorrowDetail.vue'),
        meta: {
          title: "详情页 ● 书程小驿",
          keepAlive: true
        }
      },
      {
        path: '/about',
        name: 'About',
        component: () => import(/* webpackChunkName: "about" */ '../components/Major/About.vue'),
        meta: {
          title: "我的故事 ● 书程小驿",
          keepAlive: true
        }
      },
      {
        path: '/order',
        name: 'Order',
        component: () => import(/* webpackChunkName: "about" */ '../components/Major/Order.vue'),
        meta: {
          title: "我的订单 ● 书程小驿",
          keepAlive: true
        }
      },
      {
        path: '/borrow',
        name: 'Borrow',
        component: () => import(/* webpackChunkName: "about" */ '../components/Major/Borrow.vue'),
        meta: {
          title: "我的借阅 ● 书程小驿",
          keepAlive: true
        }
      },
      {
        path: '/orderDetail',
        name: 'OrderDetail',
        component: () => import(/* webpackChunkName: "about" */ '../components/Major/OrderDetail.vue'),
        meta: {
          title: "订单详情 ● 书程小驿",
          keepAlive: true
        }
      },
      {
        path: '/individual',
        name: 'Individual',
        component: () => import(/* webpackChunkName: "about" */ '../components/Major/Individual.vue'),
        meta: {
          title: "个人中心 ● 书程小驿",
          keepAlive: true
        }
      },
      {
        path: '/search',
        name: 'Search',
        component: () => import(/* webpackChunkName: "about" */ '../components/Major/Search.vue'),
        meta: {
          title: "搜索 ● 书程小驿",
          keepAlive: true
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import(/* webpackChunkName: "about" */ '../views/LoginFrame.vue'),
    children: [
      {
        path: '/login',
        name: 'Login',
        component: () => import(/* webpackChunkName: "about" */ '../components/Login/Login.vue'),
        meta: {
          title: "用户登录",
          keepAlive: true
        }
      },
      {
        path: '/registered',
        name: 'Registered',
        component: () => import(/* webpackChunkName: "about" */ '../components/Login/Registered.vue'),
        meta: {
          title: "用户注册",
          keepAlive: true
        }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes,
})

//router.beforeEach((to, from, next)=>{
//  if (to.path !== '/Login' && to.path !== '/registered') {
//    if (sessionStorage.getItem('userInfo') === null || sessionStorage.getItem('userInfo') === '' ) {
//      next('/Login')
//    }else{
//      next()
//    }
//  } else{
//    next()
//  }
//})

router.afterEach((to)=>{
  if (to.meta.title == null || to.meta.title == "") {
    document.title = "书程小驿"
  }else{
    document.title = to.meta.title
  }
  window,scrollTo(0,0)
})

export default router
